<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <title>后台访问记录</title>
  #parse('/headFiles.html')
</head>
<body>
  <div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto" win100>
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">用户</label>
            <div class="layui-input-inline">
              <input type="text" name="managerName" placeholder="$!{i18n.get('pleaseEn')}" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">访问路径</label>
            <div class="layui-input-inline">
              <input type="text" name="path" placeholder="$!{i18n.get('pleaseEn')}" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">访问的IP</label>
            <div class="layui-input-inline">
              <input type="text" name="ip" placeholder="$!{i18n.get('pleaseEn')}" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <label class="layui-form-label">访问时间</label>
            <div class="layui-input-block">
              <input type="text" name="searchDate" id='searchDate' placeholder="$!{i18n.get('pleaseEnter')}" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
        </div>
      </div>

      <div class="layui-card-body">
        <div style="padding-bottom: 10px;">
          <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">批量删除</button>
        </div>
        <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table> 
        <script type="text/html" id="table-operate">
          	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
        </script>
      </div>
    </div>
  </div>

  #parse('/footFiles.html')
  <script>
  layui.config({
    base: '$!{webRoot}/assets/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form', 'table','laydate'], function(){
    var table = layui.table
    ,form = layui.form,laydate=layui.laydate;
    laydate.render({
      elem: '#searchDate'
      ,range: true
    });

    table.render({
      elem: '#LAY-app-content-list'
      ,url: '$!{webRoot}/sys/log/list.data'
      ,parseData: function(res){
   	    return {
   	      "code": res.code,
   	      "msg": res.msg,
   	      "count": res.body.total,
   	      "data": res.body.data
   	    };
   	  }
      ,response: {statusCode: 200}
      ,cellMinWidth:150
      ,cols: [[
        {type: 'checkbox', fixed: 'left'}
        ,{field: 'id', width: 60, title: 'ID', sort: true}
        ,{field:'managerName', title: '管理者'}
        ,{field:'path', title: '访问路径'}
        ,{field:'ip', title: '访问IP'}
        ,{field:'visitSoftwareName', title: '访问终端'}
        ,{field:'createDate', title: '访问时间'}
        ,{title: '操作',width: 90,align:'center',toolbar: '#table-operate'}
      ]]
      ,page: true
      ,limit: 20
      ,limits: [10, 15, 20, 25, 30]
    });
 
    //监听搜索
    form.on('submit(LAY-app-contlist-search)', function(data){
      var field = data.field;
      
      //执行重载
      table.reload('LAY-app-content-list', {
        where: field
       ,page: {curr:1}
      });
    });
    
    var $ = layui.$, active = {
      batchdel: function(){
        var checkStatus = table.checkStatus('LAY-app-content-list')
        ,checkData = checkStatus.data; //得到选中的数据
		let ids = '';
        if(checkData.length === 0){
          return layer.msg('请选择要删除的日志！');
        }else{
        	$(checkData).each(function(i,e){ids = ids + ',' + e.id;});
        	ids = ids.substring(1);
        }
        layer.confirm('确定要删除这些访问日志吗？', function(index) {
        	$.getJSON('$!{webRoot}/sys/log/del.do',{ids:ids},function(res){
    			if(res.code == 200){
    				table.reload('LAY-app-content-list');
    		          layer.msg('删除成功');
    			}else{
    				 layer.msg(res.msg,{icon:2});
    			}
    		});
        });
      }
    ,del:function(obj){
    	layer.confirm('确定要删除这条访问记录吗？', function(index){
    		$.getJSON('$!{webRoot}/sys/log/del.do',{ids:obj.data.id},function(res){
    			if(res.code == 200){
    				obj.del();
    	            layer.close(index);
    			}else{
    				 layer.msg(res.msg,{icon:2});
    			}
    		});
       });
    }
    }; 

    $('.layui-btn.layuiadmin-btn-list').on('click', function(){
     	let type = $(this).data('type');
      	active[type] ? active[type].call(this) : '';
    });
    
    table.on('tool(LAY-app-content-list)', function(obj){
    	let type = obj.event ;
        active[type] ? active[type].call(this,obj) : '';
    });

  });
  </script>
</body>
</html>
